package com.asistencia.businness;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.asistencia.dao.interfaces.StudentDao;
import com.asistencia.domain.Student;

@Service
public class StudentBusiness {
	
	@Autowired
	private StudentDao studentDao;
	
	@Autowired
	private Student student;
	
	public Student loginStudent(String studentCode, String password){
		try{
			student = studentDao.login( studentCode,  password);
			return student;
				
		}
		catch (Exception e) {
			System.err.println("Error traza: "+e.getMessage());
			e.printStackTrace();
			return null;
		}
	}
	public Student getById(Integer idStudent){
		
		try {
			student= studentDao.getById(idStudent);
				return student;	
			}
	
	catch (DataAccessException e){
			e.printStackTrace();
			return null;
		}}
	
public List<Student> listAll() {
	try{
		studentDao.listAll();
		List<Student> lisAll=studentDao.listAll();
		return lisAll;
	}catch(DataAccessException e){
		e.printStackTrace();
		return null;
	} catch(Exception e){
		e.printStackTrace();
		return null;
	}	
}
public List<Student> listByName(String name){
try{
	studentDao.listByName(name);
	List<Student> lstByName=studentDao.listByName(name);
	return lstByName;
	} catch (DataAccessException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	return null;
} catch(Exception e){
	e.printStackTrace();
	return null;
}
}

public List<Student> listByCareer(Integer idCareer) {
	try{
		studentDao.listByCareer(idCareer);
		List<Student> lstByCareer =studentDao.listByCareer(idCareer);
		return lstByCareer;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch(Exception e){
			e.printStackTrace();
			return null;
		}
		}	
}


